#!coding:utf-8
'''
Created on Oct 16, 2012
@author: join
福彩3D彩票测试：购买彩票，返奖
'''
from lottery_terminal.test.test_ticket import BaseTest
from lottery_terminal.service.lotteryservice import ThreaDLotteryService
from lottery_terminal.models import Account
from lottery_terminal.view.period import _do_init
import time
import logging
LOG = logging.getLogger('terminal')

threeDService = ThreaDLotteryService.ThreaDLottery()

class ThreeDTest(BaseTest):
    '''双色球测试模块，双色球的测试在本模块中完成，如：中奖,查询测试'''
        
    def test_buy(self,ticket_infos):
        threeDService.buy_ticket(ticket_infos)

    def test_zhongjiang(self):
        pass

if __name__ == '__main__':
    
    while True:
        LOG.info("===========================3D======================================")
        result = _do_init('05',30)
        periods = result.get('period')  
        lotterys=[u'2,8,4#1#1#1#2','12,5,6#1#2#1#4','2,3,4,5,6,7#3#3#1#40','5,3,8#3#1#1#2','5,6,7#2#3#1#12','5,3,3#2#1#1#2']
        tradeamount = sum([int(t.split('#')[-1]) for t in lotterys])
        accounts = Account.objects.filter(deleted=False,mac='000000000030')
        tf_accounts = Account.objects.filter(deleted=False,accountType=2)
        tianfu_account = tf_accounts[0]
        ticket_infos = {'period':periods,
                        'codes':lotterys,
                        'buymethod':2,
                        'tradeAmount':tradeamount,
                        'account':accounts[0],
                        'tianfu_account':tianfu_account,
                        'ticketobj':'TicketLoan',
                        'prizeType':0}
       
        ThreeDtest = ThreeDTest()
        ThreeDtest.test_buy(ticket_infos)
        time.sleep(3)
    
#    lotterys=[u'2,8,4#1#1#1#2','12,5,6#1#2#1#4','2,3,4,5,6,7#3#3#1#40','5,3,8#3#1#1#2','5,6,7#2#3#1#12','5,3,3#2#1#1#2']
    #单选3单式：2,8,4#1#1#1#2，单选3复式：12,5,6#1#2#1#4  
    #组选3单式：   组选3复式  
    #组选6单式：  组选6复式：
#    lotterycode = '05'
#    mac = '000101000605'
#    buymethod = 2
#    prizeType = 0
#    periodid = threeDService.get_current_period(30)
#    periodid = '2012287'
#    pricecard = 'xxx'
#    card_password = '123456'
    #实例化
#    threeDTest = ThreeDTest(lotterys=lotterys,lotterycode=lotterycode,mac=mac,buymethod=buymethod,prizeType=prizeType,
#                     periodid=periodid,pricecard=pricecard,card_password=card_password)
    #购买彩票
#    threeDTest.test_buy_lottery()